import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<Map<String, dynamic>> _listData = [
    {'imageUrl': 'images/a.jpg', 'title': 'a.jpg', 'index': 0},
    {'imageUrl': 'images/b.jpg', 'title': 'b.jpg', 'index': 1},
    {'imageUrl': 'images/c.jpg', 'title': 'c.jpg', 'index': 2},
    {'imageUrl': 'images/d.jpg', 'title': 'd.jpg', 'index': 3}
  ];

  List<Widget> _getListWidget() {
    return _listData.map((item) {
      return InkWell(
        onTap: () {
          Navigator.pushNamed(context, '/hero', arguments: {
            'listData': _listData,
            'item': item,
          });
        },
        child: Container(
          width: 200,
          decoration: BoxDecoration(
            border: Border.all(
              color: const Color.fromRGBO(233, 233, 233, 0.9),
              width: 1,
            ),
          ),
          child: Column(
            children: <Widget>[
              Hero(
                tag: item['imageUrl']!,
                child: Image.asset(
                  item['imageUrl']!,
                  fit: BoxFit.contain,
                ),
              ),
              const SizedBox(height: 10),
              Text(
                item['title']!,
                textAlign: TextAlign.center,
                style: const TextStyle(fontSize: 16),
              )
            ],
          ),
        ),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      child: Wrap(
        spacing: 15,
        runSpacing: 15,
        children: _getListWidget(),
      ),
    );
  }
}
